﻿using System;
using System.Collections.Generic;
using System.Text;

namespace svnAccessFile
{
    public class SvnRight : IEquatable<SvnRight>
    {
        public SvnRight()
        {
            CanRead = false;
            CanWrite = false;
        }
        public SvnRight(string rightString)
        {
            CanRead = rightString.Contains("r");
            CanWrite = rightString.Contains("w");
        }

        public bool CanRead {get; set; }

        public bool CanWrite { get; set; }
        public bool CanReadWrite
        {
            get
            {
                return CanRead && CanWrite;
            }
            set
            {
                CanRead = value;
                CanWrite = value;
            }
        }

        public override string ToString()
        {
            string resultString = String.Empty;
            if (CanRead)
            {
                resultString += "r";
            }
            if (CanWrite)
            {
                resultString += "w";
            }
            return resultString;
        }
        public bool Equals(SvnRight other)
        {
            return (this.CanRead == other.CanRead) && (this.CanWrite == other.CanWrite);
        }
        override public bool Equals(object other)
        {
            return Equals((SvnRight)other);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode() + CanRead.GetHashCode() + CanWrite.GetHashCode(); 
        }

    }
}
